package com.zhang.controller.system;

import cn.dev33.satoken.stp.StpUtil;
import com.zhang.common.util.result.R;
import com.zhang.common.util.result.RUtils;


import com.zhang.system.entity.Role;
import com.zhang.system.entity.UserRole;
import com.zhang.system.service.IUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 关联表：用户与角色 前端控制器
 * </p>
 *
 * @author 创世神
 * @since 2023-07-06
 */
@RestController
@RequestMapping("/userRole/")
public class UserRoleController {
    @Autowired
    IUserRoleService userRoleService;

    @PostMapping("grantUserToRole")
    public R grantUserToRole(@RequestBody UserRole userRole) {
        userRoleService.save(userRole);
        return RUtils.successMsg("用户角色添加成功");
    }


    @GetMapping("getUserToRole")
    public R getCurrentUserToRole() {
        long id = StpUtil.getLoginIdAsLong();
        List<Role> userRoleInfo = userRoleService.getUserRoleInfo(id);
        return RUtils.successData(userRoleInfo);
    }


}
